<template>
<div class="add-project-wrapper">
    <Modal :title="modalTitle"
        v-model="modalShow"
        @on-ok="save"
        @on-cancel="cancel"
        :auto-close="false"
        :mask-closable="false">
        <Form ref="form" :model="graph" :grid="1" :label-width="90" label-position="right">
            <Form-item label="所属分组">
                <Select placeholder="所属分组"  v-model="graph.projectId" class="width-md pull-left m-r-10" @on-open-change="saveProId(graph.projectId)" clearable>
                    <Option :value="item.projectId" v-for="(item,index) in projectList" :key="index" >{{item.projectName}}</Option>
                </Select>
            </Form-item>
        </Form>
    </Modal>
</div>
</template>

<script>
import util         from 'util'
import getData      from 'getData'
export default {
    data () {
        return {
            graph: {
            },
            modalShow: false,
            modalTitle: '批量分组操作',
            projectList: [],
            lastProId: null,
            idParams:{data:[]},
        }
    },
    mounted(){
        this.queryprojectList();
    },
    methods: {
        queryprojectList(){ //查询分组信息
            getData.get('queryproList').then(res =>{
                if(res.status == 200 && res.data.code == "000"){   
                    this.$set(this,"projectList",res.data.data);
                }else{
                    this.$Message.error('分组信息查询失败!');
                }
            })
        },
        cancel() {
            this.$refs.form.resetFields();
            this.modalShow = false;
        },
        save() {
            let that = this;
            that.idParams.in = that.graph.projectId
            let params = this.idParams
            let lastProId = that.lastProId
            getData.post('saveGroupForGraph',that.idParams).then((res) => {
                if (res.status == 200 && res.data.code == '000') {
                    that.$Message.success('保存批量分组成功！');
                    that.$emit("refreshGraphList",lastProId);
                    that.cancel();
                } else {
                    this.$Message.error('保存批量分组失败！');
                }
            })
        },
        show(projectId,batchGraphIdList) {
            this.idParams.data = batchGraphIdList
            this.graph.projectId = projectId;
            this.modalShow = true;
        },
        saveProId(projectId){
            //保存原来的分组id,改变分组之后刷新该分组ID的页面
            if(this.lastProId == null){
                this.lastProId = projectId;
            }
        }
    }
}
</script>
